package servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.DeviceManager;

import entities.DeviceNC;
import entities.User;

/**
 * Servlet implementation class DeviceListServlet
 */
@WebServlet("/DeviceList")
public class DeviceListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@EJB
	DeviceManager dm;
    public DeviceListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = (User) request.getSession().getAttribute("user");
		
		ArrayList<DeviceNC> devices = new ArrayList<DeviceNC>();
		devices = (ArrayList<DeviceNC>) dm.getDevices();
		request.setAttribute("devices", devices);
		
		request.getRequestDispatcher("WEB-INF/DeviceList.jsp").forward(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
